<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./template-web.js"></script>
</head>
<body>

    <!-- 定义一个容器 -->
    <div id="mydiv"></div>

    <!-- 定义一个模板 -->
    <script type="text/html" id="demo">
        <div>
            {{ each users value index}}
                <p>{{ value.id }} {{ value.name }}</p>
            {{ /each }}
        </div>
        <h4>地址:{{ address.addName }}</h4>
        <h4>爱好:{{ hobby }}</h4>
    </script>
    <script>
        var objs={
            users:[
                {
                    id:1001,
                    name:"alice1"
                },
                {
                    id:1002,
                    name:"alice2"
                },
                {
                    id:1003,
                    name:"alice3"
                }
            ],
            address:{
                addName:"南京"
            },
            hobby:"锤熊熊"
        };

        var str=template("demo",objs);
        document.getElementById("mydiv").innerHTML=str;
    </script>
</body>
</html>